package com.bytech.common.biz.entity.article;

import com.bytech.common.biz.entity.articleTag.ArticleTag;
import com.bytech.common.biz.entity.blogUser.BlogUser;
import com.bytech.common.biz.entity.blogUser.BlogUserAgent;
import com.bytech.common.biz.entity.comment.Comment;
import com.bytech.common.biz.enums.article.ArticleStatusEnum;
import com.bytech.common.biz.thirdparty.gallery.picture.GalleryPictureVo;
import com.bytech.common.utils.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Author zhao
 * @Create 2021/7/26 10:44
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ArticleDto extends Article implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer commentCount; // 评论总数
    private Boolean thumbed; // 当前是否已点赞过
    private List<Long> tagIds;
    private List<ArticleTag> tags;
    private GalleryPictureVo picture = new GalleryPictureVo();
    private List<Comment> commentList;

    public boolean isOriginal() {
        return super.getIsOriginal() != null && super.getIsOriginal();
    }

    public String getStatusDesc() {
        return ArticleStatusEnum.of(getStatus()).getDesc();
    }

    public void init() {
        if (StringUtils.isBlank(super.getId())) {
            super.setId(StringUtils.getUUID32());
        }
        super.setStatus(ArticleStatusEnum.CREATED.getValue());
        super.setViewCount(0);
        super.setThumbCount(0);
        super.setModifyTime(new Date());
        super.setCreateTime(new Date());
    }

    public ArticleStatusEnum getStatusEnum() {
        return ArticleStatusEnum.of(getStatus());
    }

    public boolean isDeleted() {
        return ArticleStatusEnum.DELETED.equals(getStatusEnum());
    }
}
